# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Contributor: Jakub Skrzypnik <j.skrzypnik@openmailbox.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=mpv
pkgver=0.34.1
pkgrel=4
pkgdesc="Video player based on MPlayer/mplayer2"
url="https://mpv.io/"
license="GPL-2.0-or-later"
arch="all"
makedepends="
	alsa-lib-dev
	cmocka-dev
	faac-dev
	ffmpeg-dev
	freetype-dev
	jack-dev
	lame-dev
	libao-dev
	libass-dev
	libbluray-dev
	libcdio-paranoia-dev
	libdvdnav-dev
	libmad-dev
	libplacebo-dev
	libtheora-dev
	libva-dev>=2.4.1
	libvdpau-dev
	libxext-dev
	libxinerama-dev
	libxkbcommon-dev
	libxrandr-dev
	libxscrnsaver-dev
	libxv-dev
	libxvmc-dev
	libxxf86dga-dev
	lua5.2-dev
	mesa-dev
	perl
	pulseaudio-dev
	py3-docutils
	python3
	shaderc-dev
	ttf-dejavu
	uchardet-dev
	vulkan-headers
	vulkan-loader-dev
	waf
	wayland-dev
	wayland-protocols
	x264-dev
	xvidcore-dev
	zlib-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-libs
	$pkgname-dev
	$pkgname-bash-completion
	$pkgname-zsh-completion
	"
source="https://github.com/mpv-player/mpv/archive/v$pkgver/mpv-$pkgver.tar.gz"

# secfixes:
#   0.27.0-r3:
#     - CVE-2018-6360

prepare() {
	default_prepare

	# Using our system waf so we don't have to download it at build time
	# This also fixes the build on riscv64
	ln -s /usr/bin/waf waf
}

build() {
	RST2HTML=rst2html-3 RST2MAN=rst2man-3 \
	python3 waf configure --prefix=/usr \
		--mandir=/usr/share/man \
		--confdir=/etc/mpv \
		--disable-build-date \
		--enable-alsa \
		--enable-jack \
		--enable-pulse \
		--enable-libmpv-shared \
		--enable-wayland \
		--enable-lua \
		--enable-test \
		--enable-vulkan \
		--enable-uchardet \
		--enable-cdda \
		--enable-dvdnav
	python3 waf build
}

check() {
	find build/test/ -perm -111 -exec '{}' ';'
}

package() {
	python3 waf install --destdir="$pkgdir"

	mkdir -p "$pkgdir"/usr/share/doc/$pkgname
	install -m644 "$builddir"/DOCS/*.rst "$builddir"/DOCS/*.md \
		"$pkgdir"/usr/share/doc/$pkgname/

	# Move example configuration files to subdirectory
	mkdir -p "$pkgdir"/usr/share/doc/mpv/examples
	mv "$pkgdir"/usr/share/doc/mpv/*.conf \
		"$pkgdir"/usr/share/doc/mpv/examples/
}

sha512sums="
77ea349d6999f8cce9b5cce4cebd3506a224fc18ab08d22dd16bd34c34d012bb170879b268ddd62db40d116b4cc0b2d9d651b8097f387ed9115c426834cac77e  mpv-0.34.1.tar.gz
"
